<?php 
require_once("class/m_report.php");
require('fpdf/fpdf.php');

class PDF extends FPDF
{
function Header()
{
    //Arial bold 15
    $this->SetFont('tahoma','B',12);
    //Title
    $this->Cell(0,10,iconv( 'UTF-8','cp874' , 'เธฃเธฒเธขเธเธฒเธเธเธฒเธฃเธเธทเธเธชเธดเธเธเนเธฒ-เธเธณเธฃเธธเธ”'),0,0,'C');
    //Line break
    $this->Ln(10);
}

//Page footer
function Footer()
{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','I',8);
    //Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'R');
}

//Colored table
function FancyTable($header,$data)
{
    //Colors, line width and bold font
    $this->SetFillColor(20,114,218);
    $this->SetTextColor(255);
    $this->SetDrawColor(114,175,242);
    $this->SetLineWidth(.1);
    $this->SetFont('','B');
    //Header
    $w=array(15,25,50,35,30);

    for($i=0;$i<count($header);$i++)
        $this->Cell($w[$i],7,iconv( 'UTF-8','cp874' , $header[$i]),0,0,'C',true);
    $this->Ln();
	
    //Color and font restoration
    $this->SetFillColor(224,235,255);
    $this->SetTextColor(0);
    $this->SetFont('');
    //Data
    $fill=false;
	$i=1;
	
    foreach($data as $row)
    {
	//	echo $row[0];
		$this->Cell($w[0],6,$i,'L',0,'R',$fill);
        $this->Cell($w[1],6,$row['ReturnDate'],'L',0,'C',$fill);
        $this->Cell($w[2],6,iconv( 'UTF-8','cp874' , $row['ProductName']),'L',0,'L',$fill);
        $this->Cell($w[3],6,$row['Type'],'LR',0,'C',$fill);
		$this->Cell($w[4],6,$row['Amounts_r'],'LR',0,'C',$fill);

        $this->Ln();
        $fill=!$fill;
		$i++;
    }
    $this->Cell(array_sum($w),0,'','T');
}
}

$report=new M_report();
$data=$report->ReturnReport();
$header=$report->ReturnHeader();
if (count($data)==0){
	echo "<script>alert('Data not found');window.close();</script>";
}
$pdf=new PDF();
$pdf->SetRightMargin(5);
$pdf->SetLeftMargin(5);
//Set pageno
$pdf->AliasNbPages();
$pdf->AddFont("tahoma","","tahoma.php");
$pdf->AddFont("tahoma","B","tahomab.php");

$pdf->SetFont("tahoma","B",10); 
$pdf->SetFont("tahoma","",10); 

//Column titles

//Data loading
$pdf->AddPage();
$pdf->FancyTable($header,$data );
$pdf->Output();
exit();
?>
